import request from '@/utils/request'

export function listStockTrading(query) {
  return request({
    url: '/stock/trading/page',
    method: 'post',
    data: query
  })
}

export function pageStockTrading(query) {
  // 分离分页参数和查询参数
  const { pageNum, pageSize, orderByColumn, isAsc, ...searchParams } = query;
  
  return request({
    url: '/stock/trading/page',
    method: 'post',
    data: searchParams, // 查询参数放在请求体中
    params: {  // 分页参数和排序参数放在URL参数中
      pageNum: pageNum,
      pageSize: pageSize,
      orderByColumn: orderByColumn,
      isAsc: isAsc
    }
  })
}

export function getStockTrading(id) {
  return request({
    url: `/stock/trading/${id}`,
    method: 'get'
  })
}

export function addStockTrading(data) {
  return request({
    url: '/stock/trading/save',
    method: 'post',
    data: data
  })
}

export function updateStockTrading(data) {
  return request({
    url: '/stock/trading/save',
    method: 'post',
    data: data
  })
}

export function delStockTrading(id) {
  return request({
    url: `/stock/trading/${id}`,
    method: 'delete'
  })
}

// 批量删除股票交易
export function batchDeleteStockTrading(ids) {
  return request({
    url: '/stock/trading/batch',
    method: 'delete',
    data: ids
  })
}

// 获取预定义的股票列表（股票编号和名称）
export function getStockList() {
  return request({
    url: '/stock/trading/stocks',
    method: 'get'
  })
}

// 同步指定日期和股票的做T收益
export function syncTProfit(tradeDate, stockCode) {
  return request({
    url: '/stock/trading/sync-t-profit',
    method: 'post',
    data: {
      tradeDate: tradeDate,
      stockCode: stockCode
    }
  })
}

// 同步指定日期所有股票的做T收益
export function syncAllTProfitByDate(tradeDate) {
  return request({
    url: '/stock/trading/sync-all-t-profit',
    method: 'post',
    data: {
      tradeDate: tradeDate
    }
  })
}

// 获取股票交易列表（不分页）
export function listAllStockTrading(query) {
  return request({
    url: '/stock/trading/list',
    method: 'post',
    data: query
  })
}

// 获取当前存在的股票（股票池股数大于待买入池股数的股票）
export function getCurrentStocks() {
  return request({
    url: '/stock/trading/current-stocks',
    method: 'get'
  })
}

// 同步单只股票状态（根据股票编码查询最新信息并检查今天的数据）
export function syncStockStatus(stockCode) {
  return request({
    url: '/stock/trading/sync-stock-status',
    method: 'post',
    data: {
      stockCode: stockCode
    }
  })
}
